\ here's the plan
\  add better literal width detection
\  code the game
\  optimize when needed
\   peephole optimization?  is it doable?
\  if things get truly annoying, upgrade to subroutine-threaded.
\

code{ u+
	tsx
	clc
	adc $102,x
	sta $102,x
	vmnext_pla
}

code{ 2!
	tax
	pla
	sta 0,x
	pla
	sta 1,x
	vmnext_pla
}

asm{
enum TEMP
	NX: .db 0
	NY: .db 0
	PX: .db 0
	PY: .db 0
ende
}


\ hardwired obj size = 16x16 for now

: solid_obj_move
;


bindlit PAD_LEFT
bindlit PAD_RIGHT
bindlit PAD_UP
bindlit PAD_DOWN
bindlit OVERWORLD_POS

bind2lit ms_player_idle_right ms_player_idle_right

bindword vx! vxstore
bindword x! xstore
bindword vy! vystore
bindword y! ystore
bindword vx@ vxfetch
bindword x@ xfetch
bindword vy@ vyfetch
bindword y@ yfetch
bindword load_screen
bindword screenxy
bindword padstate
bindword metaspr

bindword dropdup


\ todo: detect width of literal based on the length of the string;  if it's 4 or more, then it's definitely a word.

: do_player_control
	zero dup 2dup vx! vy!
	andcase dw: PAD_LEFT if $ffec vx! exit then
	andcase dw: PAD_RIGHT if $0014 vx! exit then
	andcase dw: PAD_UP if $ffec vy! exit then
	andcase dw: PAD_DOWN if $0014 vy! exit then
;

: load_overworld_screen
	OVERWORLD_POS @ load_screen
;

: do_player_world
	x@ dropdup $0f > if drop 1 OVERWORLD_POS +! 0 dup x! load_overworld_screen exit then
				  $ff < if -1 OVERWORLD_POS +! $0f00 x! load_overworld_screen exit then
	y@ dropdup $0b > if drop 4 OVERWORLD_POS +! 0 dup y! load_overworld_screen exit then
              $ff < if -4 OVERWORLD_POS +! $0b00 y! load_overworld_screen exit then
;

: doplayer
	0 padstate do_player_control drop
\	vx@ 2dup or if x@ d+ x! else 2drop then
\	vy@ 2dup or if y@ d+ y! else 2drop then
	vx@ x@ d+ x! vy@ y@ d+ y!
   do_player_world
	screenxy ms_player_idle_right metaspr
	o+
;
